package think.in.java.concurrency.PractiseOneMoreTime;

/**
 * Implement a Runnable.
 * Inside run( ), print a message, and then call yield( ).
 * Repeat this three times, and then return from run( ).
 * Put a startup message in the constructor and a shutdown message when the task terminates. Create a number of these tasks and drive them using threads
 */
public class Exec1ForRunnable implements Runnable {

    public Exec1ForRunnable(){
        System.out.println(Thread.currentThread().getName()+"Start!");
    }

    @Override
    public void run() {
       for(int i =0 ; i <3 ;i++){
            System.out.println(Thread.currentThread().getName()+"In side the thread");
           Thread.yield();
       }
        System.out.println(Thread.currentThread().getName()+"Ending");
    }

    public static void main(String[] args){
        Exec1ForRunnable[] exec1ForRunnables = new Exec1ForRunnable[3];
        for(int i =0; i <3; i++){
            exec1ForRunnables[i] = new Exec1ForRunnable();
        }
        Thread[] threads = new Thread[3];
        for(int i =0; i <3; i++){
            threads[i] = new Thread(exec1ForRunnables[i]);
        }
        for(int i =0; i <3; i++){
            threads[i].start();
        }

    }

}
